home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / Asm / Blitter / RGBPixelTrail.s < prev    next >
Encoding:
Text File  |  1998-05-07  |  5.0 KB  |  222 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;This demo demonstrates the usefulness of LISTs, by drawing a trail of
  3. ;pixels attached to the mouse.  In the case of pixels there are special
  4. ;routines for drawing with lists, so the drawing is very fast.
  5. ;
  6. ;Press LMB to exit.
  7.  
  8.     INCDIR    "GMSDev:Includes/"
  9.     INCLUDE    "dpkernel/dpkernel.i"
  10.  
  11.     SECTION    "Demo",CODE
  12.  
  13. ;===========================================================================;
  14. ;                             INITIALISE DEMO
  15. ;===========================================================================;
  16.  
  17.     STARTDPK
  18.  
  19. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  20.     move.l    DPKBase(pc),a6
  21.     lea    ScreenTags(pc),a0
  22.     sub.l    a1,a1
  23.     CALL    Init
  24.     tst.l    d0
  25.     beq.s    .Exit
  26.  
  27.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  28.     CALL    Get
  29.     move.l    d0,JoyData
  30.     beq.s    .Exit
  31.     move.l    d0,a0    ;Initialise the joydata structure.
  32.     sub.l    a1,a1
  33.     CALL    Init
  34.     tst.l    d0
  35.     beq.s    .Exit
  36.  
  37.     move.l    Screen(pc),a0
  38.     CALL    Display
  39.  
  40.     bsr.s    Main
  41.  
  42. .Exit    move.l    DPKBase(pc),a6
  43.     move.l    JoyData(pc),a0
  44.     CALL    Free
  45.     move.l    Screen(pc),a0
  46.     CALL    Free
  47.     MOVEM.L    (SP)+,A0-A6/D1-D7
  48.     moveq    #ERR_OK,d0
  49.     rts
  50.  
  51. ;===========================================================================;
  52. ;                                MAIN LOOP
  53. ;===========================================================================;
  54.  
  55. FALLSPEED =    5
  56.  
  57. SPREAD =    4
  58.  
  59. Main:    lea    MList(pc),a2    ;a2 = Pointer to pixel list.
  60. .loop    move.l    DPKBase(pc),a6
  61.     move.l    Screen(pc),a1
  62.     move.l    GS_Bitmap(a1),a0
  63.     move.l    GS_MemPtr2(a1),BMP_Data(a0)
  64.     CALL    Clear
  65.  
  66.     ;Randomize the colours and move the pixels down the screen.
  67.  
  68.     move.l    Screen(pc),a0
  69.     move.l    a2,a3    ;Drop the pixels here.
  70.     moveq    #31-1,d7
  71. .drop    moveq    #FALLSPEED,d1
  72.     CALL    FastRandom
  73.     add.w    d0,2(a3)    ;a3 = YCoord+1
  74.     move.l    DPKBase(pc),a6
  75.     move.l    #256,d1
  76.     CALL    FastRandom
  77.  
  78.     move.l    d0,d1
  79.     swap    d1
  80.     move.w    d0,d1
  81.     lsl.w    #8,d1
  82.     move.b    d0,d1
  83.  
  84.     move.l    d1,4(a3)
  85.     addq.w    #8,a3
  86.     dbra    d7,.drop
  87.  
  88.     move.l    DPKBase(pc),a6
  89.     move.l    #32000,d1
  90.     CALL    FastRandom
  91.     move.l    d0,4(a3)
  92.  
  93.     ;Move the master pixel with the mouse.
  94.  
  95.     move.l    DPKBase(pc),a6
  96.     move.l    JoyData(pc),a0
  97.     CALL    Query
  98.  
  99.     move.l    JoyData(pc),a0
  100.     move.l    JD_Buttons(a0),d0
  101.     btst    #JB_LMB,d0
  102.     bne    .done
  103.  
  104.     lea    MouseX(pc),a5
  105.     move.w    JD_YChange(a0),d0
  106.     add.w    d0,2(a5)    ;d1 = (MouseY)+ChangeY
  107.  
  108.     move.w    JD_XChange(a0),d0
  109.     add.w    (a5),d0
  110.  
  111.     move.l    Screen(pc),a0
  112. .ChkRX    cmp.w    GS_Width(a0),d0
  113.     blt.s    .ChkLX
  114.     clr.w    (a5)
  115.     bra.s    .Calculate
  116. .ChkLX    tst.w    d0
  117.     bgt.s    .okX
  118.     move.w    GS_Width(a0),(a5)
  119.     bra.s    .Calculate
  120. .okX    move.w    d0,(a5)
  121.  
  122. .Calculate
  123.     move.l    (a5),-(sp)
  124.     moveq    #SPREAD,d1
  125.     CALL    FastRandom
  126.     subq.w    #1,d0
  127.     add.w    d0,(a5)
  128.  
  129.     moveq    #SPREAD,d1
  130.     CALL    FastRandom
  131.     subq.w    #1,d0
  132.     add.w    d0,2(a5)
  133.  
  134.     lea    MList(pc),a3    ;a3 = Pixel list.
  135.     moveq    #31-1,d7    ;d7 = 31 colours [loop]
  136. .tloop    move.l    8(a3),(a3)    ;a3 = Move X/Y coordinates.
  137.     addq.w    #8,a3    ;a3 = ++8
  138.     dbra    d7,.tloop    ;d7 = --1 and loop.
  139.  
  140.     ;Now draw the pixels.
  141.  
  142.     move.l    BLTBase(pc),a6
  143.     move.l    Screen(pc),a0
  144.     move.l    GS_Bitmap(a0),a0
  145.     lea    PixelList(pc),a1    ;a1 = Pixel list.
  146.     CALL    bltDrawRGBPixelList    ;>> = Draw pixels with clipping.
  147.  
  148.     move.l    (sp)+,(a5)
  149.  
  150.     move.l    SCRBase(pc),a6
  151.     CALL    scrWaitAVBL
  152.     move.l    Screen(pc),a0
  153.     CALL    scrSwapBuffers
  154.     bra    .loop
  155.  
  156. .done    rts
  157.  
  158. ;===========================================================================;
  159. ;                                  DATA
  160. ;===========================================================================;
  161.  
  162. JoyData:    dc.l  0
  163.  
  164. ScreenTags:    dc.l  TAGS_SCREEN
  165. Screen:        dc.l  0
  166.         dc.l  GSA_Attrib,SCR_DBLBUFFER
  167.         dc.l    GSA_BitmapTags,0
  168.         dc.l    BMA_Palette,.palette
  169.         dc.l    TAGEND,0
  170.         dc.l  TAGEND
  171.  
  172. .palette    dc.l  PALETTE_ARRAY,32
  173.         dc.l  $000000,$101010,$171717,$202020,$272727,$303030,$373737,$404040
  174.         dc.l  $474747,$505050,$575757,$606060,$676767,$707070,$777777,$808080
  175.         dc.l  $878787,$909090,$979797,$a0a0a0,$a7a7a7,$b0b0b0,$b7b7b7,$c0c0c0
  176.         dc.l  $c7c7c7,$d0d0d0,$d7d7d7,$e0e0e0,$e0e0e0,$f0f0f0,$f7f7f7,$ffffff
  177.  
  178. PixelList:    dc.w   32,PXL_SIZEOF    ;Amount of entries, EntrySize.
  179.         dc.l   MList    ;Pointer to pixel list array.
  180. MList:        PIXEL  160,128,00    ;First pixel to draw (at back)
  181.         PIXEL  160,128,00    ;X/Y/Colour
  182.         PIXEL  160,128,00    ;..
  183.         PIXEL  160,128,00    ;..
  184.         PIXEL  160,128,00    ;..
  185.         PIXEL  160,128,00    ;..
  186.         PIXEL  160,128,00    ;..
  187.         PIXEL  160,128,00    ;..
  188.         PIXEL  160,128,00    ;..
  189.         PIXEL  160,128,00    ;..
  190.         PIXEL  160,128,00    ;..
  191.         PIXEL  160,128,00    ;..
  192.         PIXEL  160,128,00    ;..
  193.         PIXEL  160,128,00    ;..
  194.         PIXEL  160,128,00    ;..
  195.         PIXEL  160,128,00    ;..
  196.         PIXEL  160,128,00    ;..
  197.         PIXEL  160,128,00    ;..
  198.         PIXEL  160,128,00    ;..
  199.         PIXEL  160,128,00    ;..
  200.         PIXEL  160,128,00    ;..
  201.         PIXEL  160,128,00    ;..
  202.         PIXEL  160,128,00    ;..
  203.         PIXEL  160,128,00    ;..
  204.         PIXEL  160,128,00    ;..
  205.         PIXEL  160,128,00    ;..
  206.         PIXEL  160,128,00    ;..
  207.         PIXEL  160,128,00    ;..
  208.         PIXEL  160,128,00    ;..
  209.         PIXEL  160,128,00    ;..
  210.         PIXEL  160,128,00    ;..
  211. MouseX:        PIXEL  160,128,$ffffff    ;Last pixel to draw (in front)
  212.  
  213. ;===========================================================================;
  214.  
  215. ProgName:    dc.b  "Pixel Trail I",0
  216. ProgAuthor:    dc.b  "Paul Manias",0
  217. ProgDate:    dc.b  "April 1998",0
  218. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1998.  Freely distributable.",0
  219. ProgShort:    dc.b  "Pixel trail demonstration.",0
  220.         even
  221.  
  222.